<!DOCTYPE html>
<html lang=zh>
<head>
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="demo地址 https:&#x2F;&#x2F;gitee.com&#x2F;fengzxia&#x2F;springboot-redis-queue  1.需要的依赖12345678&lt;dependency&gt;  &lt;groupId&gt;org.springframework.boot&lt;&#x2F;groupId&gt;  &lt;artifactId&gt;spring-boot-starter&lt;&amp;#x">
<meta property="og:type" content="article">
<meta property="og:title" content="spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现">
<meta property="og:url" content="https:&#x2F;&#x2F;fengzxia.gitee.io&#x2F;posts&#x2F;1a2c31cb.html">
<meta property="og:site_name" content="只是学习学习的博客">
<meta property="og:description" content="demo地址 https:&#x2F;&#x2F;gitee.com&#x2F;fengzxia&#x2F;springboot-redis-queue  1.需要的依赖12345678&lt;dependency&gt;  &lt;groupId&gt;org.springframework.boot&lt;&#x2F;groupId&gt;  &lt;artifactId&gt;spring-boot-starter&lt;&amp;#x">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-03-28T08:17:32.000Z">
<meta property="article:modified_time" content="2020-04-16T12:11:09.382Z">
<meta property="article:author" content="只是学习学习">
<meta property="article:tag" content="订阅发布者模式">
<meta name="twitter:card" content="summary">
    
    
        
          
              <link rel="shortcut icon" href="/images/favicon.ico">
          
        
        
          
            <link rel="icon" type="image/png" href="/images/favicon-192x192.png" sizes="192x192">
          
        
        
          
            <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
          
        
    
    <!-- title -->
    <title>spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现</title>
    <!-- styles -->
    
<link rel="stylesheet" href="/css/style.css">

    <!-- persian styles -->
    
      
<link rel="stylesheet" href="/css/rtl.css">

    
    <!-- rss -->
    
    
    
<meta name="generator" content="Hexo 4.1.1"></head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
         
          <li><a href="/">主页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/categories/">分类</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/friend_ship/">友链</a></li>
        
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" href="/posts/493442a1.html"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" href="/posts/b7f6a97c.html"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">上一篇</span>
      <span id="i-next" class="info" style="display:none;">下一篇</span>
      <span id="i-top" class="info" style="display:none;">返回顶部</span>
      <span id="i-share" class="info" style="display:none;">分享文章</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://fengzxia.gitee.io/posts/1a2c31cb.html" target="_blank" rel="noopener"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://fengzxia.gitee.io/posts/1a2c31cb.html&text=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现" target="_blank" rel="noopener"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://fengzxia.gitee.io/posts/1a2c31cb.html&title=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现" target="_blank" rel="noopener"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://fengzxia.gitee.io/posts/1a2c31cb.html&is_video=false&description=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现" target="_blank" rel="noopener"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现&body=Check out this article: https://fengzxia.gitee.io/posts/1a2c31cb.html"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://fengzxia.gitee.io/posts/1a2c31cb.html&title=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现" target="_blank" rel="noopener"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://fengzxia.gitee.io/posts/1a2c31cb.html&title=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现" target="_blank" rel="noopener"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://fengzxia.gitee.io/posts/1a2c31cb.html&title=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现" target="_blank" rel="noopener"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://fengzxia.gitee.io/posts/1a2c31cb.html&title=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现" target="_blank" rel="noopener"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://fengzxia.gitee.io/posts/1a2c31cb.html&name=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现&description=" target="_blank" rel="noopener"><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://news.ycombinator.com/submitlink?u=https://fengzxia.gitee.io/posts/1a2c31cb.html&t=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现" target="_blank" rel="noopener"><i class="fab fa-hacker-news " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-需要的依赖"><span class="toc-number">1.</span> <span class="toc-text">1.需要的依赖</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-配置redis以及连接池"><span class="toc-number">2.</span> <span class="toc-text">2.配置redis以及连接池</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-创建消息的发布者和消息处理者类"><span class="toc-number">3.</span> <span class="toc-text">3.创建消息的发布者和消息处理者类</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#消息发布者"><span class="toc-number">3.1.</span> <span class="toc-text">消息发布者</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#消息处理器POJO"><span class="toc-number">3.2.</span> <span class="toc-text">消息处理器POJO</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-设置消息发布者、消息处理者POJO、redis消息监听容器以及redis监听器注入IOC容器"><span class="toc-number">4.</span> <span class="toc-text">4.设置消息发布者、消息处理者POJO、redis消息监听容器以及redis监听器注入IOC容器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-启动项目查看控制台"><span class="toc-number">5.</span> <span class="toc-text">5.启动项目查看控制台</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-如何配置多个监听通道"><span class="toc-number">6.</span> <span class="toc-text">6.如何配置多个监听通道</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#方式1：一个监听器订阅多个通道"><span class="toc-number">6.1.</span> <span class="toc-text">方式1：一个监听器订阅多个通道</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#方式2：配置多个监听器监听不同的通道"><span class="toc-number">6.2.</span> <span class="toc-text">方式2：配置多个监听器监听不同的通道</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-注入一个新的bean，名字要和之前不一样，调用-MessageReceiver-的-receiverMessage2-方法。"><span class="toc-number">6.2.1.</span> <span class="toc-text">1.注入一个新的bean，名字要和之前不一样，调用 MessageReceiver 的 receiverMessage2 方法。</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-配置监听容器，这里参数命名要和上边bean注入的方法名一致"><span class="toc-number">6.2.2.</span> <span class="toc-text">2.配置监听容器，这里参数命名要和上边bean注入的方法名一致</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-添加一个新的消息发布者"><span class="toc-number">6.2.3.</span> <span class="toc-text">3.添加一个新的消息发布者</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-启动项目打印日志如下"><span class="toc-number">6.2.4.</span> <span class="toc-text">4.启动项目打印日志如下</span></a></li></ol></li></ol></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">只是学习学习的博客</span>
      </span>
      
    <div class="postdate">
      
        <time datetime="2019-03-28T08:17:32.000Z" itemprop="datePublished">2019-03-28</time>
        
      
    </div>


      
    <div class="article-category">
        <i class="fas fa-archive"></i>
        <a class="category-link" href="/categories/Java/">Java</a> › <a class="category-link" href="/categories/Java/Redis/">Redis</a> › <a class="category-link" href="/categories/Java/Spring/">Spring</a> › <a class="category-link" href="/categories/Java/Spring/SpringBoot/">SpringBoot</a>
    </div>


      
    <div class="article-tag">
        <i class="fas fa-tag"></i>
        <a class="tag-link" href="/tags/%E8%AE%A2%E9%98%85%E5%8F%91%E5%B8%83%E8%80%85%E6%A8%A1%E5%BC%8F/" rel="tag">订阅发布者模式</a>
    </div>


    </div>
  </header>
  

  <div class="content"itemprop ="articleBody">
    <ul>
<li><strong>demo地址</strong><blockquote>
<p><a href="https://gitee.com/fengzxia/springboot-redis-queue" target="_blank" rel="noopener">https://gitee.com/fengzxia/springboot-redis-queue</a></p>
</blockquote>
<h2 id="1-需要的依赖"><a href="#1-需要的依赖" class="headerlink" title="1.需要的依赖"></a>1.需要的依赖</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependency&gt;</span><br><span class="line">  &lt;groupId&gt;org.springframework.boot&lt;&#x2F;groupId&gt;</span><br><span class="line">  &lt;artifactId&gt;spring-boot-starter&lt;&#x2F;artifactId&gt;</span><br><span class="line">&lt;&#x2F;dependency&gt;</span><br><span class="line">&lt;dependency&gt;</span><br><span class="line">  &lt;groupId&gt;org.springframework.boot&lt;&#x2F;groupId&gt;</span><br><span class="line">  &lt;artifactId&gt;spring-boot-starter-data-redis&lt;&#x2F;artifactId&gt;</span><br><span class="line">&lt;&#x2F;dependency&gt;</span><br></pre></td></tr></table></figure>
<h2 id="2-配置redis以及连接池"><a href="#2-配置redis以及连接池" class="headerlink" title="2.配置redis以及连接池"></a>2.配置redis以及连接池</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"># redis</span><br><span class="line">spring:</span><br><span class="line">  redis:</span><br><span class="line">    host: 127.0.0.1</span><br><span class="line">    port: 6379</span><br><span class="line">#    password:</span><br><span class="line">    database: 1</span><br><span class="line">    timeout: 5000</span><br><span class="line">    jedis:</span><br><span class="line">      pool:</span><br><span class="line">        max-active: 8</span><br><span class="line">        max-wait: 1</span><br><span class="line">        max-idle: 500</span><br><span class="line">        min-idle: 0</span><br></pre></td></tr></table></figure>
<h2 id="3-创建消息的发布者和消息处理者类"><a href="#3-创建消息的发布者和消息处理者类" class="headerlink" title="3.创建消息的发布者和消息处理者类"></a>3.创建消息的发布者和消息处理者类</h2><h3 id="消息发布者"><a href="#消息发布者" class="headerlink" title="消息发布者"></a>消息发布者</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@EnableScheduling</span><span class="comment">//开启定时器功能</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MessageSender</span> </span>&#123;</span><br><span class="line">  <span class="meta">@Autowired</span></span><br><span class="line">  <span class="keyword">private</span> StringRedisTemplate stringRedisTemplate;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 间隔2秒，通过stringRedisTemplate对象向redis消息队列chat频道发布消息</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="meta">@Scheduled</span>(fixedDelay = <span class="number">2000</span>)</span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">sendMessage</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    stringRedisTemplate.convertAndSend(<span class="string">"chat"</span>, String.valueOf(Math.random()));</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h3 id="消息处理器POJO"><a href="#消息处理器POJO" class="headerlink" title="消息处理器POJO"></a>消息处理器POJO</h3><ul>
<li><strong><code>@Component</code>: 自动注入，在 <code>RedisConfig</code> 中不用再写 <code>@Bean</code> 注入 <code>MessageReceiver</code></strong><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MessageReceiver</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 接收消息方法</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">receiverMessage</span><span class="params">(String message)</span> </span>&#123;</span><br><span class="line">    System.out.println(<span class="string">"MessageReceiver收到一条新消息："</span> + message);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h2 id="4-设置消息发布者、消息处理者POJO、redis消息监听容器以及redis监听器注入IOC容器"><a href="#4-设置消息发布者、消息处理者POJO、redis消息监听容器以及redis监听器注入IOC容器" class="headerlink" title="4.设置消息发布者、消息处理者POJO、redis消息监听容器以及redis监听器注入IOC容器"></a>4.设置消息发布者、消息处理者POJO、redis消息监听容器以及redis监听器注入IOC容器</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * redis配置</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> 段誉</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@create</span> 2019-03-25 9:59</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Configuration</span><span class="comment">//相当于xml中的beans</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RedisConfig</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">  <span class="meta">@Bean</span></span><br><span class="line">  <span class="function">RedisMessageListenerContainer <span class="title">container</span><span class="params">(RedisConnectionFactory connectionFactory,</span></span></span><br><span class="line"><span class="function"><span class="params">                                          MessageListenerAdapter listenerAdapter)</span> </span>&#123;</span><br><span class="line">    RedisMessageListenerContainer container = <span class="keyword">new</span> RedisMessageListenerContainer();</span><br><span class="line">    container.setConnectionFactory(connectionFactory);</span><br><span class="line">    <span class="comment">//订阅了一个叫chat的通道</span></span><br><span class="line">    container.addMessageListener(listenerAdapter, <span class="keyword">new</span> PatternTopic(<span class="string">"chat"</span>));</span><br><span class="line">    <span class="keyword">return</span> container;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 消息监听器适配器，绑定消息处理器，利用反射技术调用消息处理器的业务方法</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> receiver</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="meta">@Bean</span></span><br><span class="line">  <span class="function">MessageListenerAdapter <span class="title">listenerAdapter</span><span class="params">(MessageReceiver receiver)</span> </span>&#123;</span><br><span class="line">    <span class="comment">//给messageListenerAdapter 传入一个消息接受的处理器，利用反射的方法调用“receiveMessage”</span></span><br><span class="line">    <span class="comment">//不填defaultListenerMethod默认调用handleMessage</span></span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> MessageListenerAdapter(receiver, <span class="string">"receiverMessage"</span>);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 读取内容的template</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="meta">@Bean</span></span><br><span class="line">  <span class="function">StringRedisTemplate <span class="title">template</span><span class="params">(RedisConnectionFactory connectionFactory)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> StringRedisTemplate(connectionFactory);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="5-启动项目查看控制台"><a href="#5-启动项目查看控制台" class="headerlink" title="5.启动项目查看控制台"></a>5.启动项目查看控制台</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">MessageReceiver收到一条新消息：0.7372683821918483</span><br><span class="line">MessageReceiver收到一条新消息：0.800095651812774</span><br></pre></td></tr></table></figure>
<p>配置成功</p>
<h2 id="6-如何配置多个监听通道"><a href="#6-如何配置多个监听通道" class="headerlink" title="6.如何配置多个监听通道"></a>6.如何配置多个监听通道</h2><h3 id="方式1：一个监听器订阅多个通道"><a href="#方式1：一个监听器订阅多个通道" class="headerlink" title="方式1：一个监听器订阅多个通道"></a>方式1：一个监听器订阅多个通道</h3><p>1.监听容器配置</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Bean</span></span><br><span class="line"><span class="function">RedisMessageListenerContainer <span class="title">container</span><span class="params">(RedisConnectionFactory connectionFactory,</span></span></span><br><span class="line"><span class="function"><span class="params">                                        MessageListenerAdapter listenerAdapter)</span> </span>&#123;</span><br><span class="line">  RedisMessageListenerContainer container = <span class="keyword">new</span> RedisMessageListenerContainer();</span><br><span class="line">  container.setConnectionFactory(connectionFactory);</span><br><span class="line">  <span class="comment">//订阅了一个叫chat的通道</span></span><br><span class="line">  container.addMessageListener(listenerAdapter, <span class="keyword">new</span> PatternTopic(<span class="string">"chat"</span>));</span><br><span class="line">  </span><br><span class="line">  container.addMessageListener(listenerAdapter, <span class="keyword">new</span> PatternTopic(<span class="string">"chat1"</span>));</span><br><span class="line">  <span class="keyword">return</span> container;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>2.添加一个新的消息发布者</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@EnableScheduling</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MessageSender</span> </span>&#123;</span><br><span class="line">  <span class="meta">@Autowired</span></span><br><span class="line">  <span class="keyword">private</span> StringRedisTemplate stringRedisTemplate;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 间隔2秒，通过stringRedisTemplate对象向redis消息队列chat1频道发布消息</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="meta">@Scheduled</span>(fixedDelay = <span class="number">2000</span>)</span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">sendMessage1</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    stringRedisTemplate.convertAndSend(<span class="string">"chat1"</span>, String.valueOf(Math.random()));</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="meta">@Scheduled</span>(fixedDelay = <span class="number">2000</span>)</span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">sendMessage2</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    stringRedisTemplate.convertAndSend(<span class="string">"chat2"</span>, String.valueOf(System.currentTimeMillis()));</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>3.启动项目查看控制台打印</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">MessageReceiver收到一条新消息：0.9988032526665156</span><br><span class="line">MessageReceiver收到一条新消息：来自chat1的消息0.5760191019007642</span><br><span class="line">MessageReceiver收到一条新消息：0.37241454741448377</span><br><span class="line">MessageReceiver收到一条新消息：来自chat1的消息0.639498468451238</span><br></pre></td></tr></table></figure>
<p>说明配置成功</p>
<h3 id="方式2：配置多个监听器监听不同的通道"><a href="#方式2：配置多个监听器监听不同的通道" class="headerlink" title="方式2：配置多个监听器监听不同的通道"></a>方式2：配置多个监听器监听不同的通道</h3><h4 id="1-注入一个新的bean，名字要和之前不一样，调用-MessageReceiver-的-receiverMessage2-方法。"><a href="#1-注入一个新的bean，名字要和之前不一样，调用-MessageReceiver-的-receiverMessage2-方法。" class="headerlink" title="1.注入一个新的bean，名字要和之前不一样，调用 MessageReceiver 的 receiverMessage2 方法。"></a>1.注入一个新的bean，名字要和之前不一样，调用 <code>MessageReceiver</code> 的 <code>receiverMessage2</code> 方法。</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Bean</span></span><br><span class="line"><span class="function">MessageListenerAdapter <span class="title">listenerAdapter2</span><span class="params">(MessageReceiver receiver)</span> </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="keyword">new</span> MessageListenerAdapter(receiver, <span class="string">"receiverMessage2"</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>这里也可以自己新注入一个新的 <code>Receiver</code> 叫 <code>MessageReceiver2</code><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MessageReceiver2</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 接收消息方法</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">receiverMessage</span><span class="params">(String message)</span> </span>&#123;</span><br><span class="line">    System.out.println(<span class="string">"MessageReceiver收到一条新消息："</span> + message);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Bean</span></span><br><span class="line"><span class="function">MessageListenerAdapter <span class="title">listenerAdapter2</span><span class="params">(MessageReceiver2 receiver)</span> </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="keyword">new</span> MessageListenerAdapter(receiver, <span class="string">"receiverMessage"</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h4 id="2-配置监听容器，这里参数命名要和上边bean注入的方法名一致"><a href="#2-配置监听容器，这里参数命名要和上边bean注入的方法名一致" class="headerlink" title="2.配置监听容器，这里参数命名要和上边bean注入的方法名一致"></a>2.配置监听容器，<strong>这里参数命名要和上边bean注入的方法名一致</strong></h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Bean</span></span><br><span class="line"><span class="function">RedisMessageListenerContainer <span class="title">container</span><span class="params">(RedisConnectionFactory connectionFactory,</span></span></span><br><span class="line"><span class="function"><span class="params">                                        MessageListenerAdapter listenerAdapter1,</span></span></span><br><span class="line"><span class="function"><span class="params">                                        MessageListenerAdapter listenerAdapter2)</span> </span>&#123;</span><br><span class="line">  RedisMessageListenerContainer container = <span class="keyword">new</span> RedisMessageListenerContainer();</span><br><span class="line">  container.setConnectionFactory(connectionFactory);</span><br><span class="line">  <span class="comment">//订阅了一个叫chat的通道</span></span><br><span class="line">  container.addMessageListener(listenerAdapter1, <span class="keyword">new</span> PatternTopic(<span class="string">"chat"</span>));</span><br><span class="line">  container.addMessageListener(listenerAdapter2, <span class="keyword">new</span> PatternTopic(<span class="string">"chat1"</span>));</span><br><span class="line">  <span class="keyword">return</span> container;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="3-添加一个新的消息发布者"><a href="#3-添加一个新的消息发布者" class="headerlink" title="3.添加一个新的消息发布者"></a>3.添加一个新的消息发布者</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//开启定时器功能</span></span><br><span class="line"><span class="meta">@EnableScheduling</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MessageSender</span> </span>&#123;</span><br><span class="line">  <span class="meta">@Autowired</span></span><br><span class="line">  <span class="keyword">private</span> StringRedisTemplate stringRedisTemplate;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 间隔2秒，通过stringRedisTemplate对象向redis消息队列chat1频道发布消息</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="meta">@Scheduled</span>(fixedDelay = <span class="number">2000</span>)</span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">sendMessage1</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    stringRedisTemplate.convertAndSend(<span class="string">"chat1"</span>, String.valueOf(Math.random()));</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="meta">@Scheduled</span>(fixedDelay = <span class="number">2000</span>)</span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">sendMessage2</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    stringRedisTemplate.convertAndSend(<span class="string">"chat2"</span>, String.valueOf(System.currentTimeMillis()));</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="4-启动项目打印日志如下"><a href="#4-启动项目打印日志如下" class="headerlink" title="4.启动项目打印日志如下"></a>4.启动项目打印日志如下</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">收到一条chat2新消息：1555564092816</span><br><span class="line">收到一条chat1新消息：0.257614690680789</span><br><span class="line">收到一条chat2新消息：1555564094830</span><br><span class="line">收到一条chat1新消息：0.3996585101720651</span><br><span class="line">收到一条chat2新消息：1555564096833</span><br><span class="line">收到一条chat1新消息：0.6767629866464419</span><br><span class="line">收到一条chat2新消息：1555564098836</span><br><span class="line">收到一条chat1新消息：0.14106474791507906</span><br></pre></td></tr></table></figure>
<p>配置成功</p>

<div id="gitalk-container"></div>
<script src="https://cdn.bootcss.com/blueimp-md5/2.12.0/js/md5.min.js"></script><link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css"><script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>

		<script>
		var gitalkConfig = {"clientID":"28a065e3b5afee156f4f","clientSecret":"e18104d6f3219526491fc42c892ff6a26b8f3e74","repo":"blog_comment","owner":"FENG1000","admin":["FENG1000"],"distractionFreeMode":false};
	    gitalkConfig.id = md5(location.pathname);
		var gitalk = new Gitalk(gitalkConfig);
	    gitalk.render("gitalk-container");
	    </script>
    
  <blockquote>
      <p>
          作者: 只是学习学习<br>
          邮箱: fengzxia1000@163.com<br>
          原文地址: <a href="https://fengzxia.gitee.io/posts/1a2c31cb.html" target="_blank" rel="noopener">https://fengzxia.gitee.io/posts/1a2c31cb.html</a><br>
          版权声明: 商业转载请联系作者获得授权，非商业转载请注明出处。
      </p>
  </blockquote>

  <script>
      function setClipboardText(event){
          // clipboardData 对象是为通过编辑菜单、快捷菜单和快捷键执行的编辑操作所保留的，也就是你复制或者剪切内容
          let clipboardData = event.clipboardData || window.clipboardData;
          // 如果未复制或者未剪切，则return出去
          if (!clipboardData) { return; }
          event.preventDefault();
          // Selection 对象，表示用户选择的文本范围或光标的当前位置。
          //     声明一个变量接收 -- 用户输入的剪切或者复制的文本转化为字符串
          let text = window.getSelection().toString();

          if (text) {
            // 如果文本存在则先取消文本默认事件
            event.preventDefault();
            // 通过调用常clipboardData对象的 setData(format, data) 方法；来设置相关文本
            // format: 一个DOMString 表示要添加到 drag object的拖动数据的类型。
            // data: 一个 DOMString表示要添加到 drag object的数据。
            var copyright = '\n\n'
                            + '\n著作权归作者所有。'
                            + '\n商业转载请联系作者获得授权，非商业转载请注明出处。'
                            + '\n作者: 只是学习学习'
                            + '\n邮箱: fengzxia1000@163.com'
                            + '\n原文地址: https://fengzxia.gitee.io/posts/1a2c31cb.html'

            clipboardData.setData('text/plain', text + copyright);

          }
      };
      var contents = document.getElementsByClassName("content");
      // 监听文章内容的copy事件
      contents[0].addEventListener('copy',function(e){
          setClipboardText(e);
      });
  </script>

  </div>
</article>




        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">主页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/categories/">分类</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/friend_ship/">友链</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-需要的依赖"><span class="toc-number">1.</span> <span class="toc-text">1.需要的依赖</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-配置redis以及连接池"><span class="toc-number">2.</span> <span class="toc-text">2.配置redis以及连接池</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-创建消息的发布者和消息处理者类"><span class="toc-number">3.</span> <span class="toc-text">3.创建消息的发布者和消息处理者类</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#消息发布者"><span class="toc-number">3.1.</span> <span class="toc-text">消息发布者</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#消息处理器POJO"><span class="toc-number">3.2.</span> <span class="toc-text">消息处理器POJO</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-设置消息发布者、消息处理者POJO、redis消息监听容器以及redis监听器注入IOC容器"><span class="toc-number">4.</span> <span class="toc-text">4.设置消息发布者、消息处理者POJO、redis消息监听容器以及redis监听器注入IOC容器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-启动项目查看控制台"><span class="toc-number">5.</span> <span class="toc-text">5.启动项目查看控制台</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-如何配置多个监听通道"><span class="toc-number">6.</span> <span class="toc-text">6.如何配置多个监听通道</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#方式1：一个监听器订阅多个通道"><span class="toc-number">6.1.</span> <span class="toc-text">方式1：一个监听器订阅多个通道</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#方式2：配置多个监听器监听不同的通道"><span class="toc-number">6.2.</span> <span class="toc-text">方式2：配置多个监听器监听不同的通道</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-注入一个新的bean，名字要和之前不一样，调用-MessageReceiver-的-receiverMessage2-方法。"><span class="toc-number">6.2.1.</span> <span class="toc-text">1.注入一个新的bean，名字要和之前不一样，调用 MessageReceiver 的 receiverMessage2 方法。</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-配置监听容器，这里参数命名要和上边bean注入的方法名一致"><span class="toc-number">6.2.2.</span> <span class="toc-text">2.配置监听容器，这里参数命名要和上边bean注入的方法名一致</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-添加一个新的消息发布者"><span class="toc-number">6.2.3.</span> <span class="toc-text">3.添加一个新的消息发布者</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-启动项目打印日志如下"><span class="toc-number">6.2.4.</span> <span class="toc-text">4.启动项目打印日志如下</span></a></li></ol></li></ol></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://fengzxia.gitee.io/posts/1a2c31cb.html" target="_blank" rel="noopener"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://fengzxia.gitee.io/posts/1a2c31cb.html&text=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现" target="_blank" rel="noopener"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://fengzxia.gitee.io/posts/1a2c31cb.html&title=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现" target="_blank" rel="noopener"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://fengzxia.gitee.io/posts/1a2c31cb.html&is_video=false&description=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现" target="_blank" rel="noopener"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现&body=Check out this article: https://fengzxia.gitee.io/posts/1a2c31cb.html"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://fengzxia.gitee.io/posts/1a2c31cb.html&title=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现" target="_blank" rel="noopener"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://fengzxia.gitee.io/posts/1a2c31cb.html&title=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现" target="_blank" rel="noopener"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://fengzxia.gitee.io/posts/1a2c31cb.html&title=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现" target="_blank" rel="noopener"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://fengzxia.gitee.io/posts/1a2c31cb.html&title=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现" target="_blank" rel="noopener"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://fengzxia.gitee.io/posts/1a2c31cb.html&name=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现&description=" target="_blank" rel="noopener"><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://news.ycombinator.com/submitlink?u=https://fengzxia.gitee.io/posts/1a2c31cb.html&t=spring-boot集成redis实现消息发布订阅模式，以及多个订阅模式的实现" target="_blank" rel="noopener"><i class="fab fa-hacker-news fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> 菜单</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> 目录</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> 分享</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> 返回顶部</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy;
    
    
    2019-2020
    只是学习学习
  </div>
  <div class="footer-right">
    <nav>
      <ul>
         
          <li><a href="/">主页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/categories/">分类</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/friend_ship/">友链</a></li>
        
      </ul>
    </nav>
  </div>
</footer>

    </div>
    <!-- styles -->

<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">


<link rel="stylesheet" href="/lib/justified-gallery/css/justifiedGallery.min.css">


    <!-- jquery -->

<script src="/lib/jquery/jquery.min.js"></script>


<script src="/lib/justified-gallery/js/jquery.justifiedGallery.min.js"></script>

<!-- clipboard -->

  
<script src="/lib/clipboard/clipboard.min.js"></script>

  <script type="text/javascript">
  $(function() {
    // copy-btn HTML
    var btn = "<span class=\"btn-copy tooltipped tooltipped-sw\" aria-label=\"复制到粘贴板!\">";
    btn += '<i class="far fa-clone"></i>';
    btn += '</span>'; 
    // mount it!
    $(".highlight table").before(btn);
    var clip = new ClipboardJS('.btn-copy', {
      text: function(trigger) {
        return Array.from(trigger.nextElementSibling.querySelectorAll('.code')).reduce((str,it)=>str+it.innerText+'\n','')
      }
    });
    clip.on('success', function(e) {
      e.trigger.setAttribute('aria-label', "复制成功!");
      e.clearSelection();
    })
  })
  </script>


<script src="/js/main.js"></script>

<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

    <script type="text/javascript">
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?54382acbd8c4bc66535bce135e0ac166";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>

<!-- Disqus Comments -->


</body>
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https'){
   bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
  }
  else{
  bp.src = 'http://push.zhanzhang.baidu.com/push.js';
  }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>
</html>
